<html>
<head><meta charset="utf-8"><title>Soveu · new members · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122652-new-members/index.html">new members</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122652-new-members/topic/Soveu.html">Soveu</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="206473668"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122652-new%20members/topic/Soveu/near/206473668" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/122652-new-members/topic/Soveu.html#206473668">(Aug 10 2020 at 15:21)</a>:</h4>
<p>Hey, I've been mainly sitting on #black-magic on discord, but there were too many links to this place, so here I am.</p>
<p>My currently biggest achievement: speeding up <code>tinyvec</code> 3 to 10 times in some cases</p>
<p>On <a href="https://github.com/Soveu">my github</a> you'll mostly find small or unfinished stuff, mainly because I started to learn rust like 4 months ago, let alone contribute to the first crate which was Loka's <code>safe_arch</code><br>
With C/C++ background it was a quite smooth transition, considering how many things are done differently here in Rust</p>
<p>Right at the moment I'm exploring lock-free/parallel data structures<br>
I'm fresh high school graduate, but I know a bit about binary exploitation and algorithms (got into semi-finals of national high school programming competition)<br>
I would love to get hired at least for the time before academic year starts, but I still haven't even started writing my resume/CV (mainly because there is little to write just after high school)</p>



<a name="206486379"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122652-new%20members/topic/Soveu/near/206486379" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122652-new-members/topic/Soveu.html#206486379">(Aug 10 2020 at 17:10)</a>:</h4>
<p>That's awesome!</p>



<a name="206486422"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122652-new%20members/topic/Soveu/near/206486422" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122652-new-members/topic/Soveu.html#206486422">(Aug 10 2020 at 17:11)</a>:</h4>
<p>I did my PhD on parallel data structures, and I'm always glad to see people working in that area. Happy to talk algorithms and data structures some time. :)</p>



<a name="206486461"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122652-new%20members/topic/Soveu/near/206486461" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122652-new-members/topic/Soveu.html#206486461">(Aug 10 2020 at 17:11)</a>:</h4>
<p>Those sound like some impressive performance improvements for tinyvec.</p>



<a name="206486506"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122652-new%20members/topic/Soveu/near/206486506" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122652-new-members/topic/Soveu.html#206486506">(Aug 10 2020 at 17:11)</a>:</h4>
<p>Might some of those be applicable to smallvec in the Rust compiler?</p>



<a name="206486732"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122652-new%20members/topic/Soveu/near/206486732" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122652-new-members/topic/Soveu.html#206486732">(Aug 10 2020 at 17:13)</a>:</h4>
<p>Also, the Rust compiler has some support for parallel compilation.</p>



<a name="206486832"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122652-new%20members/topic/Soveu/near/206486832" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122652-new-members/topic/Soveu.html#206486832">(Aug 10 2020 at 17:14)</a>:</h4>
<p>And if you are interested in a optimization challenge, rayon needs help with scalability past somewhere in the 32 thread range.</p>



<a name="206499058"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122652-new%20members/topic/Soveu/near/206499058" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/122652-new-members/topic/Soveu.html#206499058">(Aug 10 2020 at 18:57)</a>:</h4>
<p>Well, really it was a really trivial optimization, not to call it dead simple</p>
<div class="codehilite"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">extend</span><span class="p">(</span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="bp">self</span><span class="p">,</span><span class="w"> </span><span class="n">iter</span>: <span class="nc">impl</span><span class="w"> </span><span class="nb">Iterator</span><span class="o">&lt;</span><span class="n">Item</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="bp">Self</span>::<span class="n">Item</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="k">for</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">iter</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="bp">self</span><span class="p">.</span><span class="n">push</span><span class="p">(</span><span class="n">x</span><span class="p">);</span><span class="w"></span>
<span class="w">  </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>


<p>meanwhile <code>push()</code> perform first a check whether tinyvec is inline or on heap, if it has enough space, and then performs the push<br>
I just changed it to</p>
<div class="codehilite"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">extend</span><span class="p">(</span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="bp">self</span><span class="p">,</span><span class="w"> </span><span class="n">iter</span>: <span class="nc">impl</span><span class="w"> </span><span class="nb">Iterator</span><span class="o">&lt;</span><span class="n">Item</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="bp">Self</span>::<span class="n">Item</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="kd">let</span><span class="w"> </span><span class="n">arr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">match</span><span class="w"> </span><span class="bp">self</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">TinyVec</span>::<span class="n">Inline</span><span class="p">(</span><span class="n">a</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="n">a</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">TinyVec</span>::<span class="n">Heap</span><span class="p">(</span><span class="n">h</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">h</span><span class="p">.</span><span class="n">extend</span><span class="p">(</span><span class="n">iter</span><span class="p">),</span><span class="w"></span>
<span class="w">  </span><span class="p">};</span><span class="w"></span>

<span class="w">  </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">iter</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">arr</span><span class="p">.</span><span class="n">fill</span><span class="p">(</span><span class="n">iter</span><span class="p">);</span><span class="w"></span>
<span class="w">  </span><span class="kd">let</span><span class="w"> </span><span class="n">item</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">match</span><span class="w"> </span><span class="n">iter</span><span class="p">.</span><span class="n">next</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="nb">Some</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="n">x</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="nb">None</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="k">return</span><span class="p">,</span><span class="w"></span>
<span class="w">  </span><span class="p">};</span><span class="w"></span>
<span class="w">  </span><span class="kd">let</span><span class="w"> </span><span class="n">hint</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">iter</span><span class="p">.</span><span class="n">size_hint</span><span class="p">().</span><span class="mi">0</span><span class="p">;</span><span class="w"></span>
<span class="w">  </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">v</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">Vec</span>::<span class="n">with_capacity</span><span class="p">(</span><span class="n">arr</span><span class="p">.</span><span class="n">len</span><span class="p">()</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">hint</span><span class="p">);</span><span class="w"></span>
<span class="w">  </span><span class="n">v</span><span class="p">.</span><span class="n">extend</span><span class="p">(</span><span class="n">arr</span><span class="p">.</span><span class="n">drain</span><span class="p">(</span><span class="o">..</span><span class="p">));</span><span class="w"></span>
<span class="w">  </span><span class="n">v</span><span class="p">.</span><span class="n">push</span><span class="p">(</span><span class="n">item</span><span class="p">);</span><span class="w"></span>
<span class="w">  </span><span class="n">v</span><span class="p">.</span><span class="n">extend</span><span class="p">(</span><span class="n">iter</span><span class="p">);</span><span class="w"></span>
<span class="w">  </span><span class="o">*</span><span class="bp">self</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">TinyVec</span>::<span class="n">Heap</span><span class="p">(</span><span class="n">v</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>


<p>And boom, 3x to 5x boost on iterators (on a synthetic benchmark, but still)</p>



<a name="206499590"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122652-new%20members/topic/Soveu/near/206499590" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/122652-new-members/topic/Soveu.html#206499590">(Aug 10 2020 at 19:01)</a>:</h4>
<p>smallvec has this downside that it isn't an enum that you can simply match like tinyvec, but also tinyvec provides its own 100% safe version of arrayvec, which requires the type to be <code>Default</code>, because on <code>drain</code>, <code>pop</code> and similar functions it <code>mem::take</code>s elements, so it isn't as efficient</p>



<a name="206500057"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122652-new%20members/topic/Soveu/near/206500057" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/122652-new-members/topic/Soveu.html#206500057">(Aug 10 2020 at 19:04)</a>:</h4>
<p>One big advantage over smallvec is that tinyvec from 1.0 can hold more bytes inline, because it is an enum of <code>(u16, Array)</code> and <code>Vec</code></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>